package com.dykj.fireFighting.server.base.government.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dykj.fireFighting.api.base.government.entity.GovProOther;
import com.dykj.fireFighting.api.base.government.entity.GovernmentProcess;
import com.dykj.fireFighting.api.base.government.entity.GovernmentProject;
import com.dykj.fireFighting.api.base.government.service.IGovernmentProcessService;
import com.dykj.fireFighting.api.base.government.service.IGovernmentProjectService;
import com.dykj.fireFighting.server.base.government.mapper.GovernmentProcessMapper;
import com.dykj.fireFighting.server.base.government.mapper.GovernmentProjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service("GovernmentProcessServiceImpl")
@DubboService
@Transactional(rollbackFor = Exception.class)
public class GovernmentProcessServiceImpl extends ServiceImpl<GovernmentProcessMapper, GovernmentProcess>  implements IGovernmentProcessService {
    @Override
    public void sb(List<GovernmentProcess> governmentProcessList){
        saveOrUpdateBatch(governmentProcessList);
    }
    @Override
    public List<GovernmentProcess> getListByPid(String pid){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("pid",pid);
        return list(queryWrapper);
    }

    @Override
    public int getCountByDateC7(String stDate, String endDate) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.select("sum(c7) as c7");
        queryWrapper.between("create_time",stDate,endDate);
        GovernmentProcess governmentProcess=getOne(queryWrapper);
        return governmentProcess==null?0:governmentProcess.getC7();
    }
    @Override
    public int getCountByDateC8(String stDate, String endDate) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.select("sum(c8) as c8");
        queryWrapper.between("create_time",stDate,endDate);
        GovernmentProcess governmentProcess=getOne(queryWrapper);
        return governmentProcess==null?0:governmentProcess.getC8();
    }
    @Override
    public List<GovernmentProcess> getZlcg(String stDate, String endDate) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.select("DATE_FORMAT(create_time,'%Y年%m月') as create_time,SUM(c7) AS c7,SUM(c8) AS c8");
        queryWrapper.between("create_time",stDate,endDate);
        queryWrapper.groupBy("DATE_FORMAT(create_time,'%Y年%m月')");
        return list(queryWrapper);
    }

    @Override
    public List<GovernmentProcess> getXmsj(String pid) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.select("sum(c2) as c2,sum(c3) as c3,sum(c4) as c4,sum(c5) as c5,sum(c6) as c6");
        queryWrapper.eq("pid",pid);
        return list(queryWrapper);
    }
}
